/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {TreeNode} root
 * @param {number} k
 * @return {number}
 */
 var kthLargest = function(root, k) {
  let count = 0
  function findNode(root1){
    if(root1 === null) return
    let right = findNode(root1.right)
    if(right) return right
    count++
    if(count === k){
      return root1.val
    }
    let left = findNode(root1.left)
    if(left) return left
  }
  let res = findNode(root)
  return res ? res : -1
};